package weixinkeji.dev.dc.buy.order.h.fwy;

import sys.wx.ann.hm.M;
import sys.wx.ann.power.head.SQ;
import sys.wx.c.ATR;
import sys.wx.c.components.cv.CV;
import sys.wx.m.db.dao.mysql.Dao;
import weixinkeji.dev.dc.DCPower;
import weixinkeji.dev.dc.base.scheme.combo.bean.Combo;
import weixinkeji.dev.dc.base.scheme.promotions.bean.PromotionDay;
import weixinkeji.dev.dc.base.scheme.promotions.so.PromotionDaySO;
import weixinkeji.dev.dc.buy.order.bean.FWYOrderB;
import weixinkeji.dev.dc.buy.order.h.fwy.vo.FWYOrderBVO;
import weixinkeji.dev.dc.buy.order.h.fwy.vo.check.CheckFWYCarVo;
import weixinkeji.dev.dc.buy.order.so.FWYOrderSO;
import weixinkeji.dev.dc.buy.order.xy.FWYOrderXY;

@sys.wx.ann.hm.H("view/buy/order/fwy/kd/u")

//身份类型授权。无需人工付权。
//代表 是服务员才能进行访问。
@SQ(DCPower.ID_FWY)
public class FWYKDBHU {

    //查询未结账的单据。
    @M("/updateOneOrderb")//通过 view/buy/order/fwy/kd/u/updateOneOrderb.imy 访问
    synchronized public static String updaet(ATR a) {

        FWYOrderBVO bvo = CV.getObjectByFields(FWYOrderBVO.class, a.request, CheckFWYCarVo.doCar_FWYOrderB());
        if (null == bvo) {
            return null;
        }
        FWYOrderB bobj = Dao.selectOneByID(FWYOrderB.class, bvo.orderb_id);
        if (null == bobj.getOrderb_id()) {
            return null;
        } else if (bobj.getBuy_number() + bvo.number < 0) {
            a.printOne("如果要开负单、退单，请通知管理员");
            return null;
        }
        bobj.setBuy_number(bobj.getBuy_number() + bvo.number);
        bobj.setBuy_sum(bobj.getBuy_price() * 1000 * bobj.getBuy_number() / 1000);

        switch (bobj.getOrderb_style()) {
            case FWYOrderXY.B_STYLE_3:
            case FWYOrderXY.B_STYLE_4:
            case FWYOrderXY.B_STYLE_2: {
                a.printOne("清单已锁定，无法变动。如果非要变动，请联系管理员。");
                return null;
            }
            case FWYOrderXY.B_STYLE_1: {
                switch (Integer.parseInt(bobj.getSource_sort())) {
                    case FWYOrderXY.B_SOURCE_SORT_COMBO: {
                        Combo combo = Dao.selectOneByID(Combo.class, bobj.getSource_id());
                        switch (Integer.parseInt(combo.getCombo_style())) {
                            case 1: {
                                a.printOne(FWYOrderSO.updateOrderB(bobj) ? "1" : "修改失败，请联系管理员1");
                                return null;
                            }
                            default: {
                                a.printOne("套餐非启用状态，无法操作");
                                return null;
                            }
                        }
                    }
                    case FWYOrderXY.B_SOURCE_SORT_FOOD: {
                        a.printOne(FWYOrderSO.updateOrderB(bobj) ? "1" : "修改失败，请联系管理员2");
                        return null;
                    }
                    case FWYOrderXY.B_SOURCE_SORT_PROMOTIONDAY: {
                        PromotionDay pdobj = PromotionDaySO.getPromotionDay(bobj.getSource_id());
                        if (pdobj.getPromotion_now_number() < bvo.number) {
                            a.printOne("对不起，活动数据不足，无法操作");
                            return null;
                        }
                        a.printOne(FWYOrderSO.updateOrderB_PromotionDay(bobj, bvo.number) ? "1" : "修改失败，请稍后再尝试");
                        return null;
                    }
                }
            }
        }
        return null;
    }

}
